Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/model/src/commonMain/kotlin/org/meshtastic/core/model/geofence/Geofence.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.54 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.model.geofence

Tff7b72import T7ee787org.meshtastic.core.common.util.latLongToMeter
Tff7b72import T7ee787org.meshtastic.core.model.util.GeoConstants.DEG_D
Tff7b72import T7ee787org.meshtastic.proto.Waypoint

T8b949e/** A circular geofence centered on [centerLat]/[centerLon] (decimal degrees) with [radiusMeters]. */
Tff7b72data Tff7b72class T56d364GeofenceCircleTb4b4b4(Tff7b72val Te6edf3centerLatTb4b4b4: Tffa657DoubleTb4b4b4, Tff7b72val Te6edf3centerLonTb4b4b4: Tffa657DoubleTb4b4b4, Tff7b72val Te6edf3radiusMetersTb4b4b4: Tffa657IntTb4b4b4) Tb4b4b4{
T8b949e/** True when ([lat], [lon]) is within [radiusMeters] great-circle metres of the centre. */
Tff7b72fun Td2a8ffcontainsTb4b4b4(Te6edf3latTb4b4b4: Tffa657DoubleTb4b4b4, Te6edf3lonTb4b4b4: Tffa657DoubleTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3latLongToMeterTb4b4b4(Te6edf3latTb4b4b4, Te6edf3lonTb4b4b4, Te6edf3centerLatTb4b4b4, Te6edf3centerLonTb4b4b4) Tff7b72<Tff7b72= Te6edf3radiusMeters
Tb4b4b4}

T8b949e/** An axis-aligned WSEN bounding box in decimal degrees. Bounds are inclusive (matches the Apple reference). */
Tff7b72data Tff7b72class T56d364GeofenceBoxTb4b4b4(Tff7b72val Te6edf3southTb4b4b4: Tffa657DoubleTb4b4b4, Tff7b72val Te6edf3westTb4b4b4: Tffa657DoubleTb4b4b4, Tff7b72val Te6edf3northTb4b4b4: Tffa657DoubleTb4b4b4, Tff7b72val Te6edf3eastTb4b4b4: Tffa657DoubleTb4b4b4) Tb4b4b4{
Tff7b72fun Td2a8ffcontainsTb4b4b4(Te6edf3latTb4b4b4: Tffa657DoubleTb4b4b4, Te6edf3lonTb4b4b4: Tffa657DoubleTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3lat Tff7b72in Te6edf3southTb4b4b4.Tb4b4b4.Te6edf3north Tff7b72&Tff7b72& Te6edf3lon Tff7b72in Te6edf3westTb4b4b4.Tb4b4b4.Te6edf3east
Tb4b4b4}

T8b949e/**
* A waypoint's geofence region: a [circle] and/or a [box]. A point is inside if it is in EITHER shape (OR semantics) —
* both may be set, either may be null.
*/
Tff7b72data Tff7b72class T56d364GeofenceTb4b4b4(Tff7b72val Te6edf3circleTb4b4b4: Te6edf3GeofenceCircle?Tb4b4b4, Tff7b72val Te6edf3boxTb4b4b4: Te6edf3GeofenceBox?Tb4b4b4) Tb4b4b4{
Tff7b72fun Td2a8ffcontainsTb4b4b4(Te6edf3latTb4b4b4: Tffa657DoubleTb4b4b4, Te6edf3lonTb4b4b4: Tffa657DoubleTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72=
Tb4b4b4(Te6edf3circleTff7b72?.Te6edf3containsTb4b4b4(Te6edf3latTb4b4b4, Te6edf3lonTb4b4b4) Tff7b72=Tff7b72= Tff7b72trueTb4b4b4) Tff7b72|Tff7b72| Tb4b4b4(Te6edf3boxTff7b72?.Te6edf3containsTb4b4b4(Te6edf3latTb4b4b4, Te6edf3lonTb4b4b4) Tff7b72=Tff7b72= Tff7b72trueTb4b4b4)
Tb4b4b4}

T8b949e/** True when this waypoint asks receivers to raise crossing notifications. */
Tff7b72val Te6edf3WaypointTb4b4b4.Te6edf3notifiesOnCrossingTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3notify_on_enter Tff7b72|Tff7b72| Te6edf3notify_on_exit

T8b949e/**
* Decode this waypoint's geofence region, or null when it defines neither a circle nor a box. This is the single source
* of the proto `×1e-7 → decimal-degree` conversion, shared by the alert engine, the map overlays, and the editor — keep
* all geofence coordinate decoding here so the three consumers cannot drift.
*/
Tff7b72fun Te6edf3WaypointTb4b4b4.Td2a8fftoGeofenceTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3Geofence? Tb4b4b4{
Tff7b72val Te6edf3circle Tff7b72=
Tff7b72if Tb4b4b4(Te6edf3geofence_radius Tff7b72> T79c0ff0Tb4b4b4) Tb4b4b4{
Te6edf3GeofenceCircleTb4b4b4(Tb4b4b4(Te6edf3latitude_i Tff7b72?: T79c0ff0Tb4b4b4) Tff7b72* Te6edf3DEG_DTb4b4b4, Tb4b4b4(Te6edf3longitude_i Tff7b72?: T79c0ff0Tb4b4b4) Tff7b72* Te6edf3DEG_DTb4b4b4, Te6edf3geofence_radiusTb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Tff7b72null
Tb4b4b4}
Tff7b72val Te6edf3box Tff7b72=
Te6edf3bounding_boxTff7b72?.Te6edf3let Tb4b4b4{
Tff7b72val Te6edf3southDeg Tff7b72= Tffa657itTb4b4b4.Te6edf3latitude_south_i Tff7b72* Te6edf3DEG_D
Tff7b72val Te6edf3northDeg Tff7b72= Tffa657itTb4b4b4.Te6edf3latitude_north_i Tff7b72* Te6edf3DEG_D
Tff7b72val Te6edf3westDeg Tff7b72= Tffa657itTb4b4b4.Te6edf3longitude_west_i Tff7b72* Te6edf3DEG_D
Tff7b72val Te6edf3eastDeg Tff7b72= Tffa657itTb4b4b4.Te6edf3longitude_east_i Tff7b72* Te6edf3DEG_D
T8b949e// Normalize transposed corners so an inverted box (south>north / west>east) from another client still
T8b949e// describes the intended rectangle. (Antimeridian-crossing boxes remain a documented non-goal.)
Te6edf3GeofenceBoxTb4b4b4(
Te6edf3south Tff7b72= Te6edf3minOfTb4b4b4(Te6edf3southDegTb4b4b4, Te6edf3northDegTb4b4b4)Tb4b4b4,
Te6edf3west Tff7b72= Te6edf3minOfTb4b4b4(Te6edf3westDegTb4b4b4, Te6edf3eastDegTb4b4b4)Tb4b4b4,
Te6edf3north Tff7b72= Te6edf3maxOfTb4b4b4(Te6edf3southDegTb4b4b4, Te6edf3northDegTb4b4b4)Tb4b4b4,
Te6edf3east Tff7b72= Te6edf3maxOfTb4b4b4(Te6edf3westDegTb4b4b4, Te6edf3eastDegTb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tff7b72return Tff7b72if Tb4b4b4(Te6edf3circle Tff7b72=Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3box Tff7b72=Tff7b72= Tff7b72nullTb4b4b4) Tff7b72null Tff7b72else Te6edf3GeofenceTb4b4b4(Te6edf3circleTb4b4b4, Te6edf3boxTb4b4b4)
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s